package erupt_simultaneously;

import java.util.concurrent.atomic.LongAdder;

/**
 * @Auther Jun jie Yi
 * @Date 10:56 2021/8/1
 */
public class LongAdderDemo {
    public static void main(String[] args) throws InterruptedException {

        LongAdder longAdder = new LongAdder();

        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                longAdder.add(1);
                System.out.println(longAdder.longValue());
            }
        });
        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                longAdder.add(1);
                System.out.println(longAdder.longValue());
            }
        });

        thread1.start();
        thread2.start();

        thread1.join();
        thread2.join();
    }
}
